package com.pdwl.controller;

import com.pdwl.common.dtos.*;
import com.pdwl.pojo.AuthUser;
import com.pdwl.service.AuthUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @Description: 后台用户控制层
 * @Author: TLB
 * @Date: 2023/1/11 10:42
 */
@RestController
@RequestMapping("/api/user")
@Api(tags = "管理端用户")
public class AuthUserController {


    @Autowired
    private AuthUserService authUserService;

    /**
     * 生成验证码
     * @return
     */
    @GetMapping("/captcha")
    @ApiOperation("验证码功能")
    @ApiImplicitParam(value = "redis的key    登录请求再次发送同一个key",
            name = "key",
            example = "key=1D9074FE682555FACBF347021673429811956",
            required = true)
    public void captcha(String key, HttpServletResponse response){
         authUserService.captcha(key,response);
    }


    /**
     * 用户登录验证
     * @param loginDto
     * @return
     */
    @PostMapping("/login_auth")
    @ApiOperation("用户登录")
//    @ApiResponse(code = 200,message = "操作成功",response = ResponseResult.class)
    public ResponseResult<Map<String,Object>> login(@RequestBody LoginDto loginDto) {
        return authUserService.login(loginDto);
    }

    /**
     * 新增
     * @param authUser
     * @return
     */
    @PostMapping
    @ApiOperation("新增用户")
    public ResponseResult add(AuthUser authUser){
        return authUserService.add(authUser);
    }

    /**
     * 分页展示
     * @return
     */
    @PostMapping("/page")
    @ApiOperation("分页查询用户")
    public PageResponseResult<List<AuthUser>> findPage(@RequestBody PageRequestDto<AuthUserDto> pageRequestDto){
        return authUserService.findPage(pageRequestDto);
    }

}
